{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## algorithm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "fac = lambda i, *j: i and fac(*divmod(i, len(j) + 1), *j) or j or (i,)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "dec = lambda i, k=0, *j: j and dec(i * len(j) + i + k, *j) or i"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## run"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 <-> 0\n",
      "1 <-> 1 0\n",
      "8 <-> 1 1 0 0\n",
      "27 <-> 1 0 1 1 0\n",
      "64 <-> 2 2 2 0 0\n",
      "125 <-> 1 0 0 2 1 0\n",
      "216 <-> 1 4 0 0 0 0\n",
      "343 <-> 2 4 1 0 1 0\n",
      "512 <-> 4 1 1 1 0 0\n",
      "729 <-> 1 0 0 1 1 1 0\n",
      "1000 <-> 1 2 1 2 2 0 0\n"
     ]
    }
   ],
   "source": [
    "for i in range(0, 11):\n",
    "    f = fac(i ** 3)\n",
    "    d = dec(*f)\n",
    "    print(d, '<->', ' '.join(map(str, f)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 1, 4, 1, 2, 2, 1, 0)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fac(6281)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6281"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dec(*(1, 1, 4, 1, 2, 2, 1, 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
